package com.develop.data.loan.manager.change.amount;

import com.develop.data.loan.manager.change.amount.api.LoanInstallmentAmountClear;
import com.develop.data.loan.model.LoanInstallment;
import org.springframework.stereotype.Component;

import javax.money.MonetaryAmount;
import java.time.LocalDateTime;

@Component("L0001B0001LoanInstallmentPrincipalOverdueClear")
public class L0001B0001LoanInstallmentPrincipalOverdueClear implements LoanInstallmentAmountClear {

    /* 已发生形态转移 */
    /* 持有时间，左受制于动帐时间，右受制于转非应计时间（不计息） */
    /* LoanInstallmentPrincipalOverdue对应Installment的PrincipalOverdue金额字段 */

    public MonetaryAmount preview(LoanInstallment loanInstallment, LocalDateTime localDate){
        return loanInstallment.getInstallmentPrincipalOverdue();
    }

    public void execute(LoanInstallment loanInstallment, LocalDateTime localDate){
        MonetaryAmount amountPreviewed = this.preview(loanInstallment, localDate);
        loanInstallment.setInstallmentPrincipalOverdue(loanInstallment.getInstallmentPrincipalOverdue().subtract(amountPreviewed));
        loanInstallment.setInstallmentPrincipalCleared(loanInstallment.getInstallmentPrincipalCleared().add(amountPreviewed));
    }

}
